package com.bosssoft.permission.centre.service.impl;


import com.alibaba.fastjson.JSONObject;
import com.bosssoft.permission.centre.entity.User;
import com.bosssoft.permission.centre.service.TokenService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: wang
 * @description:
 * @param
 */
@Slf4j
@Service
public class TokenServiceImpl implements TokenService {

    @Override
    public String getToken(User user, User userInfo, String account, List<Long> roleIds) {
        final JSONObject header = new JSONObject();
        final JSONObject playLoad = new JSONObject();
        header.put("alg", "HS256");
        header.put("typ", "JWT");

        playLoad.put("account",account);
        playLoad.put("roleIds", roleIds);
        playLoad.put("tenantId", user.getTenantId());
        playLoad.put("companyId", user.getCompanyId());
        playLoad.put("orgId", user.getOrgId());
        playLoad.put("userId", userInfo.getId());
        playLoad.put("userName", user.getName());
        String token = header.toJSONString() + "."+ playLoad.toJSONString();
        return token;
    }
}
